package vista;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import controlador.ControladorAC;
import dto.BarraDTO;
import dto.RecetaDTO;
import dto.SucursalDTO;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AltaBarra extends javax.swing.JFrame {
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JTextField nombre;
	private JComboBox<String> sucursal;
	private JLabel jLabel5;
	private JButton cancelar;
	private JButton aceptar;
	private JComboBox empleado;
	private JComboBox deposito;
	private JLabel jLabel4;
	private JLabel jLabel3;
	List<SucursalDTO> listaSucursales;
	

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AltaBarra inst = new AltaBarra();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public AltaBarra() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Alta Barra");
				jLabel1.setBounds(35, 20, 168, 16);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("Nombre");
				jLabel2.setBounds(32, 79, 67, 16);
			}
			{
				nombre = new JTextField();
				getContentPane().add(nombre);
				nombre.setBounds(114, 76, 188, 23);
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("Sucursal");
				jLabel3.setBounds(32, 125, 66, 16);
			}
			{

				sucursal = new JComboBox<String>();;
				getContentPane().add(sucursal);
				listaSucursales = ControladorAC.getInstancia().listarSucursales();
				for(SucursalDTO s: listaSucursales){
					sucursal.addItem(s.getNombre());
				}
				sucursal.setBounds(114, 122, 188, 23);
			}
			{
				jLabel4 = new JLabel();
				getContentPane().add(jLabel4);
				jLabel4.setText("Deposito");
				jLabel4.setBounds(29, 176, 59, 16);
			}
			{
				ComboBoxModel depositoModel = 
						new DefaultComboBoxModel(
								new String[] { "Item One", "Item Two" });
				deposito = new JComboBox();
				getContentPane().add(deposito);
				deposito.setModel(depositoModel);
				deposito.setBounds(114, 173, 188, 23);
			}
			{
				jLabel5 = new JLabel();
				getContentPane().add(jLabel5);
				jLabel5.setText("Empleado");
				jLabel5.setBounds(29, 223, 65, 16);
			}
			{
				ComboBoxModel empleadoModel = 
						new DefaultComboBoxModel(
								new String[] { "Item One", "Item Two" });
				empleado = new JComboBox();
				getContentPane().add(empleado);
				empleado.setModel(empleadoModel);
				empleado.setBounds(114, 220, 188, 23);
			}
			{
				aceptar = new JButton();
				getContentPane().add(aceptar);
				aceptar.setText("Aceptar");
				aceptar.setBounds(266, 282, 80, 23);
				aceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						
						SucursalDTO s = new SucursalDTO();
						for(SucursalDTO suc: listaSucursales){
							if(suc.getNombre().equalsIgnoreCase((String) sucursal.getSelectedItem())){
								s = suc;
							}
						}
						BarraDTO b = new BarraDTO();
						b.setNombre(nombre.getText());
						ControladorAC.getInstancia().altaBarra(s, b);
					}
				});
			}
			{
				cancelar = new JButton();
				getContentPane().add(cancelar);
				cancelar.setText("Cancelar");
				cancelar.setBounds(373, 282, 91, 23);
				cancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("cancelar.actionPerformed, event="+evt);
						//TODO add your code for cancelar.actionPerformed
					}
				});
			}
			pack();
			this.setSize(517, 366);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
